import config
import time
from dateutil import rrule
from datetime import datetime
from bubbles.NEMTCountdownQuery import NEMTCountdownQuery
from utils import *


def register():
	return NEMTCountdown()


class NEMTCountdown:
	def __init__(self):
		self.type = 'active'
		self.countdown = NEMTCountdownQuery()
		self.last = 0

	def run(self, gum):
		now = time.time()
		if now - self.last <= config.bubbles.NEMTCountdown.gap \
				or time.localtime(now).tm_hour != config.bubbles.NEMTCountdown.hour:
			return
		self.last = now

		chain = MsgChain()
		chain.addPlain(f'糖糖提醒您，距离高考还有{self.countdown.calc()}天')

		sendFriends(chain, config.bubbles.NEMTCountdown.friends)
		sendGroups(chain, config.bubbles.NEMTCountdown.groups)
